<?php
/**
 * Vacations History
 * View to search through vacation table to display user history.
 * 
 * @author Xavier VILAIN
 * @package hive
 * @subpackage vacations
 */

use Hive\Vacation\Sheet;
use Hive\Vacation\Status;
use Fox\Grid;
use Hive\Vacation\Type;
use Fox\Dao\SqlFragment;
use Fox\Html\DropList;
use Fox\Html\Interval;
use Fox\Html\Screen;

// Status
$finder = new Status();
$status = $finder->find(new SqlFragment("language = ?",array(Xview::instance()->language())));

// Types
$finder = new Type();
$types = $finder->find(new SqlFragment("language = ?",array(Xview::instance()->language())));

$screen = new Screen("sSearch","vlook");
$block = new Fox\Html\Block("bSearch",Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_SEARCH_CRITERIA));
$block->add(new Interval("period"));
$block->add(new DropList(array("vacation_status","status"),true))
		->options($status);
$block->add(new DropList(array("vacation_type","type"),true))
		->options($status);
$screen->add($block);
if($screen->submitted())
{
	$fields = $screen->get();
	if(!$screen->errors())
	{
		$grid = new Grid("history");
		$grid->fieldcat(array(
						array("vacation_type","type"),
						"start_date",
						"end_date",
						"number_of_days",
						array("vacation_comments","comments"),
						"status"
						));
		$grid->fieldcat()->switchToObjectMode();
		$finder = new Sheet();
		$result = $finder->find(SqlFragment::combine($fragments));
		$grid->initialize($result,true);
		$ouput = $grid->display();
	}
}
echo $screen->display();
if(isset($ouput))
{
	echo $ouput;
}